import { createStore } from "vuex";

export default createStore({
  state() {
    return {
      blogList: {
        blogList: [
          {
            id: 1,
            name: '我的第一篇博客',
            tag: ['New'],
            datetime: '1639553151',
            desc: 'Make it so.'
          },
          {
            id: 2,
            name: 'My second blog',
            tag: ['Top'],
            datetime: '1639553198',
            desc: 'Cur aonides peregrinatione?'
          },
          {
            id: 3,
            name: 'My third blog',
            tag: [],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 4,
            name: 'My 4 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 5,
            name: 'My 5 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 6,
            name: 'My 6 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 7,
            name: 'My 7 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 8,
            name: 'My 8 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 9,
            name: 'My 9 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 10,
            name: 'My 10 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 11,
            name: 'My 11 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          },
          {
            id: 12,
            name: 'My 12 blog',
            tag: ['Top', 'New', 'Hot'],
            datetime: '1639560594',
            desc: 'This is my third blog, huh-huh!'
          }
        ],
        blogDetail: [
          {
            id: 1,
            content: ['The particle is more astronaut now than nanomachine. calm and cunningly cloudy.A falsis, triticum fatalis vox.', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 2,
            content: ['Vital anomalies lead to the devastation.', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 3,
            content: ['Particles view with resistance!', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 4,
            content: ['Death is an old anchor.', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 5,
            content: ['The cosmonaut is more particle now than nanomachine. distant and nosily neutral.', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 6,
            content: ['2333333', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 7,
            content: ['2333333', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 8,
            content: ['2333333', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 9,
            content: ['2333333', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 10,
            content: ['2333333', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 11,
            content: ['Nunquam perdere clabulare.Mensas sunt ignigenas de brevis extum.Cobaltums volare!', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          },
          {
            id: 12,
            content: ['2333333', 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!',
              '  Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, laborum? Adipisci voluptatum id consectetur alias nobis, nihil aut dolorum? Illo cupiditate quia dicta natus vitae dignissimos veniam aut repellat sint!']
          }
        ]
      },
      mine: {
        data: {
          username: '洛明',
          img: '../static/imgs/avatar.png',
          school: 'Zhengzhou University of Aeronautics | 郑州航空航天大学',
          desc: '这里是洛明，喜欢编程还有一切有意思的东西✨',
        }
      },
      checkin: {
        moodList: [
          {
            date: '2021/12/15',
            mood: 'Nice'
          },
          {
            date: '2021/12/14',
            mood: 'Normal'
          },
          {
            date: '2021/12/13',
            mood: 'Bad'
          }
        ]
      },
      record: {
        recordList: [
          {
            id: 1,
            name: 'lorem',
            content: '这个网站好棒！'
          },
          {
            id: 2,
            name: 'bubo ',
            content: 'The mind is full of sorrow.'
          }, {
            id: 3,
            name: 'culina ',
            content: 'THE COW KNOWS.'
          }, {
            id: 4,
            name: 'ratione ',
            content: '这个网站好厉害！'
          }, {
            id: 5,
            name: 'particula ',
            content: 'Magnum voxs ducunt ad cannabis.'
          },
        ]
      }
    }
  },
  actions: {},
  getters: {
    getAllBlog: state => {
      return state.blogList.blogList
    },
    getTotal: state => {
      return state.blogList.blogList.length
    },
    getCurrentPageContent: state => (currentPage, pageSize) => {
      return state.blogList.blogList.slice(pageSize * (currentPage - 1), currentPage * pageSize)
    },
    getBlogDetail: state => (id) => {
      let blogContent = state.blogList.blogDetail.filter(item => item.id === id)[0]
      let blogInfo = state.blogList.blogList.filter(item => item.id === id)[0]
      let blogDetail = {}
      Object.assign(blogDetail, blogContent)
      Object.assign(blogDetail, blogInfo)
      return blogDetail
    },
    getMineData: state => {
      return state.mine.data
    },
    getMood: state => {
      return state.checkin.moodList.map(value => {
        let _value = {}
        Object.assign(_value, value)
        _value.date = value.date.replaceAll('/', '-')
        return _value
      })
    },
    getRecordList: state => {
      return state.record.recordList
    }
  },
  mutations: {
    submitMood(state, moodListItem) {
      state.checkin.moodList.push(moodListItem)
    },
    addRecord(state, recordListItem) {
      state.record.recordList.push(recordListItem)
    },
    removeBlog(state, id) {
      let cmp = state.blogList.blogDetail.findIndex(value => value.id === id)
      state.blogList.blogDetail.splice(cmp, 1)
      state.blogList.blogList.splice(cmp, 1)
    },
    addBlogInfo(state, blogInfo) {
      state.blogList.blogList.push(blogInfo)
    },
    addBlogDetail(state, blogDetail) {
      state.blogList.blogDetail.push(blogDetail)
    },
    updateBlogInfo(state, blogInfo) {
      let find = state.blogList.blogList.find(value => value.id === blogInfo.id)
      find.desc = blogInfo.desc
      find.tag = blogInfo.tag
      find.name = blogInfo.name
      find.datetime = blogInfo.datetime
    },
    updateBlogDetail(state, blogDetail) {
      let find = state.blogList.blogDetail.find(value => value.id === blogDetail.id)
      find.content = blogDetail.content
    }
  }
})

